package xyf.p01.array_nodelist;

import commons.ListNode;

/**
 * ClassName: P0206_Reverse
 * Description:
 * Author: xyf
 * Date: 9/3/22 10:49 AM
 * Version: 1.0
 **/
public class P0206_Reverse
{
    public ListNode reverseList(ListNode head)
    {
        if(head == null || head.next == null){
            return head;
        }
        ListNode pre = null;
        ListNode cur = head;
        while (cur != null)
        {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }
}
